<?php
class Model_UserPost extends Model{

    public function getPraiseInfo($userid,$offset,$pageSize){

        $sql="select p.postid id,p.title,p.description,p.images,p.view,p.review,p.created,p.wish,p.praiseup,p.praisedown
            from
            (
                select i.postid
                from interact i
                where  i.userid='$userid'
                group by i.postid
                order by i.createdon desc limit $offset,$pageSize
            )t
            left join post p on p.postid=t.postid
            ";

        $data=DB::query(Database::SELECT,$sql)->execute()->as_array();

        return $data;

    }

    public function getPraiseItems($userid){

        $total= DB::select(array(DB::expr('count(distinct postid)'), 'total'))

         ->from('interact')

        ->where('type','=','praiseup')

        ->and_where("userid","=",$userid)

        ->execute()

        ->get("total");

        return $total;

    }

    public function getReviewInfo($userid,$offset,$pageSize){

        $sql="select p.postid id,p.title,p.description,p.images,p.view,p.review,p.created,p.wish,p.praiseup,p.praisedown
            from
            (
                select postid
                from review r
                where  r.userid='$userid'
                group by r.postid
                order by r.createdon desc limit $offset,$pageSize
            )t
            left join post p on p.postid=t.postid";

        $data=DB::query(Database::SELECT,$sql)->execute()->as_array();

        return $data;

    }


    public function getReviewItems($userid){

        $total= DB::select(array(DB::expr('count(distinct postid)'), 'total'))

         ->from('review')

        ->where('userid','=',$userid)

        ->execute()

        ->get("total");

        return $total;

    }
}